<template>
  <page-header-wrapper>
    <page-tab-list>
      <div class="table-page-search-box">
        <a-form layout="inline">
          <a-row :gutter="24">
            <a-col :md="8" :sm="24">
              <a-form-item label="商户名称">
                <a-input placeholder="请输入商户名称" v-model="queryParam.name"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="员工名称">
                <a-input placeholder="请输入员工名称" v-model="queryParam.salesman"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="">
                <a-button type="primary" @click="getShopList">查询</a-button>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </page-tab-list>
    <a-card :bordered="false" class="card_style_re">
      <div class="table-operator" style="display: flex; justify-content: space-between">
        <a-radio-group v-model="queryParam.status" @change="getShopList">
          <a-radio-button value="-1"> 全部 </a-radio-button>
          <a-radio-button value="0"> 待审核 </a-radio-button>
          <a-radio-button value="1"> 审核中 </a-radio-button>
          <a-radio-button value="2"> 已驳回 </a-radio-button>
          <a-radio-button value="3"> 已完成 </a-radio-button>
        </a-radio-group>
      </div>
      <a-table
        :rowKey="
          (r, i) => {
            return r.id
          }
        "
        :pagination="{
          total: this.totalCount,
          showSizeChanger: false,
          onChange: this.tablePageChange,
        }"
        :columns="columns"
        :data-source="shopList"
      >
        <div slot="name" slot-scope="text, record">
          <div class="name">
            <div class="pic">
              <img :src="record.store_logo" alt="" v-if="record.store_logo" />
              <img src="../../assets/images/diy/goodExample.png" alt="" v-else />
            </div>
            <div class="info">
              <span>{{ record.store_name || '-' }}</span>
              <span>{{ record.cat_name || '-' }}</span>
            </div>
          </div>
        </div>
        <div slot="status" slot-scope="scope">
          <div class="status">
            <span
              :class="
                scope.status == 0
                  ? 'status1'
                  : scope.status == 1
                  ? 'status2'
                  : scope.status == 2
                  ? 'status3'
                  : 'status4'
              "
            ></span>
            <span>{{
              scope.status == 0 ? '待审核' : scope.status == 1 ? '审核中' : scope.status == 2 ? '已驳回' : '已完成'
            }}</span>
          </div>
        </div>
        <span slot="sub_mch_id" slot-scope="text">
          {{ text && text != '' ? text : '-' }}
        </span>
      </a-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { merchantList } from '@/api/saas/setting'
import defaultImg from '@/assets/images/diy/goodExample.png'
const columns = [
  {
    title: '店铺信息',
    width: 300,
    scopedSlots: {
      customRender: 'name',
    },
  },
  {
    title: '申请编号',
    dataIndex: 'business_code',
  },
  {
    title: '商户号',
    dataIndex: 'sub_mch_id',
    scopedSlots: {
      customRender: 'sub_mch_id',
    },
  },
  {
    title: '创建员工',
    dataIndex: 'name',
  },
  {
    title: '状态',
    width: 120,
    scopedSlots: {
      customRender: 'status',
    },
  },
]

export default {
  data() {
    return {
      // 查询参数
      queryParam: {
        name: null,
        salesman: null,
        status: '-1',
        pageNo: 1,
        pageSize: 10,
      },
      // 已选中行的id
      selectedRowKeys: [],
      // 门店列表
      shopList: [],
      columns,
      // 数据总条数
      totalCount: 0,
    }
  },
  methods: {
    // 获取进件列表
    async getShopList() {
      const hide = this.$message.loading('加载中', 0)
      const res = await merchantList(this.queryParam)
      console.log(res)
      if (res.code == 0) {
        this.totalCount = res.data.totalCount
        this.shopList = res.data.data
      }
      hide()
    },
    // 分页请求
    tablePageChange(e) {
      this.queryParam.pageNo = e
      this.getShopList()
    },
    // 同意或拒绝门店申请
    audit(id, statua) {
      let that = this
      let text = statua == 1 ? '通过' : '拒绝'
      this.$confirm({
        title: '是否' + text + '申请?',
        async onOk() {
          that.batchAudit([id], statua)
        },
        onCancel() {},
      })
    },
    // 批量操作门店
    async batchAudit(id, shop_audit) {
      const res = await batchAudit({
        id,
        shop_audit,
      })
      if (res.code == 0) {
        this.getShopList()
      }
    },
    // 点击批量同意或拒绝
    allAudit(statua) {
      if (this.selectedRowKeys.length) {
        let that = this
        this.$confirm({
          title: '是否' + statua == 1 ? '通过' : '拒绝' + '申请?',
          async onOk() {
            that.batchAudit(that.selectedRowKeys, statua)
          },
          onCancel() {},
        })
      }
    },
  },
  created() {
    this.getShopList()
  },
}
</script>

<style lang="less" scoped>
.searchBox {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  /deep/ .ant-input-affix-wrapper {
    width: 220px;
    margin-top: 14px;
    margin-right: 20px;
  }
  .select {
    display: flex;
    align-items: center;
    margin-top: 14px;
    margin-right: 20px;
  }
  .ant-btn {
    margin-top: 14px;
  }
}
.name {
  display: flex;
  align-items: center;
  .pic {
    width: 48px;
    min-width: 48px;
    height: 48px;
    border-radius: 4px;
    overflow: hidden;
    margin-right: 24px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .info {
    flex: auto;
    width: 0;
    display: flex;
    flex-direction: column;
    font-size: 14px;
    span {
      width: 100%;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    span:nth-child(2) {
      color: rgba(0, 0, 0, 0.45);
      margin-top: 6px;
    }
  }
}
.status {
  display: flex;
  align-items: center;
  span:nth-child(1) {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 4px;
  }
  .status1 {
    background-color: #eeb041;
  }
  .status2 {
    background-color: #438ef7;
  }
  .status3 {
    background-color: #eb5b56;
  }
  .status4 {
    background-color: #7ec640;
  }
}
</style>